/*
 * CRecordStore.h
 *
 *  Created on: 2018年5月17日
 *      Author: zhengboyuan
 */

#ifndef CRecordStore_H_
#define CRecordStore_H_

#include "RecordStore.h"
#include "DataStore.h"
#include "TThread.h"
#include "RecordClearThread.h"


namespace av
{


class CRecordStore: public av::RecordStore, public RecordClearSink
{
public:
    CRecordStore();
    virtual ~CRecordStore();


    virtual bool open(const char* dbpath);

    virtual void close();

    virtual bool isOpen();

    virtual int findRecord(const MRecordQuery& query, int offset, MRecord* records, int size);

	virtual int countRecord(const MRecordQuery& query);

	virtual bool getRecord(int id, av::MRecord& record);

    virtual bool deleteRecord(int id);

    virtual bool deleteRecordWithFileName(const char* filename);

    virtual bool findRecordWithFileName(const char* filename, MRecord* record);

    virtual void clearBrokenRecord(const char* chl);

    void deleteRecord(av::MRecord& record);

protected:
    virtual void onRecordCleared(const std::string& chl, int cleared);

protected:
    DataStorePtr    m_dataStore;
    std::string m_dbpath;

    std::shared_ptr< comn::Thread > m_clearThread;

};


}
#endif /* CRecordStore_H_ */
